package com.web.dao;

import com.web.VO.MyDemandVO;
import com.web.VO.MyPublishVO;
import com.web.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DemandInfoMapper {
    @Delete({
        "delete from APP_DEMAND_INFO",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into APP_DEMAND_INFO (user_id, demand_type, ",
        "is_expedited, modile, ",
        "longitude, latitude, ",
        "demand_description, videos, ",
        "first_video_photos, photos, ",
        "audio, create_time, ",
        "modify_time, is_invalid, ",
        "is_topping, is_review)",
        "values (#{userId,jdbcType=VARCHAR}, #{demandType,jdbcType=INTEGER}, ",
        "#{isExpedited,jdbcType=INTEGER}, #{modile,jdbcType=VARCHAR}, ",
        "#{longitude,jdbcType=VARCHAR}, #{latitude,jdbcType=VARCHAR}, ",
        "#{demandDescription,jdbcType=VARCHAR}, #{videos,jdbcType=VARCHAR}, ",
        "#{firstVideoPhotos,jdbcType=VARCHAR}, #{photos,jdbcType=VARCHAR}, ",
        "#{audio,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{modifyTime,jdbcType=TIMESTAMP}, #{isInvalid,jdbcType=INTEGER}, ",
        "#{isTopping,jdbcType=INTEGER}, #{isReview,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(DemandInfo record);

    int insertSelective(DemandInfo record);

    @Select({
        "select",
        "id, user_id, demand_type, is_expedited, title, modile, longitude, latitude, demand_description, ",
        "videos, first_video_photos, photos, audio, create_time, modify_time, share_num, is_invalid, ",
        "is_topping, is_review, create_by, modify_by",
        "from APP_DEMAND_INFO",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    DemandInfo selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(DemandInfo record);

    @Update({
        "update APP_DEMAND_INFO",
        "set user_id = #{userId,jdbcType=VARCHAR},",
          "demand_type = #{demandType,jdbcType=INTEGER},",
          "is_expedited = #{isExpedited,jdbcType=INTEGER},",
          "modile = #{modile,jdbcType=VARCHAR},",
          "longitude = #{longitude,jdbcType=VARCHAR},",
          "latitude = #{latitude,jdbcType=VARCHAR},",
          "demand_description = #{demandDescription,jdbcType=VARCHAR},",
          "videos = #{videos,jdbcType=VARCHAR},",
          "first_video_photos = #{firstVideoPhotos,jdbcType=VARCHAR},",
          "photos = #{photos,jdbcType=VARCHAR},",
          "audio = #{audio,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "modify_time = #{modifyTime,jdbcType=TIMESTAMP},",
          "is_invalid = #{isInvalid,jdbcType=INTEGER},",
          "is_topping = #{isTopping,jdbcType=INTEGER},",
          "is_review = #{isReview,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(DemandInfo record);


    List<DemandInfo> getAllDemandInfo();

    DemandInfoDetails getDemandInfoDetails(@Param("demandId") Integer demandId, @Param("userId") String userId);

    int updateByPrimary(InstantInfoDemand instantInfo);

    List<UserDemand> UserDemand(String userId);

    /**
     * 我发布的需求
     * @param userId
     * @return
     */
    List<MyPublishVO> listMyPublishDemand(@Param("userId") String userId);

    MyDemand findMyDemand(@Param("userId")String userId,@Param("typeId") Integer typeId);

    void DeleteMyDemand(@Param("typeId") Integer typeId);
}